<template>
    <div id="mark">
        <div id="confirm">
            <div class="top">
                <label for="">服务名称</label> <input id="uri" type="text" v-model="name" >
                <label for="">服务地址</label> <input id="appid" type="text" v-model="url">
            </div>
            <div class="middle">
                <div v-for="item in recordLists" :ket="item.id" @click="selectAPP(item)"
                    :class="{ selected: name == item.name }">
                    <img :src="item.thumbnail ? item.thumbnail : imgUrl" width="80"
                        height="80" />
                    <p :title="item.name">{{ item.name }}</p>
                </div>
            </div>
            <div class="footer">
                <el-button @click="cancel">取消</el-button>
                <el-button @click="confirm">确定</el-button>
            </div>
        </div>
    </div>
</template>


<script setup lang="ts">
import { getProjectManager } from "@/scripts/getProjectManager";
import { createVueDisposer, toVR } from "earthsdk-ui";
import { onBeforeUnmount, ref, onMounted, computed, watch, nextTick } from 'vue';
import { ApplyType } from "../scripts/dataTypes";

const imgUrl = new URL("../assets/switchEngine/fail.png", import.meta.url).href


const objm = getProjectManager();
const d = createVueDisposer(onBeforeUnmount)

const emit = defineEmits(["confirm", "cancel"])

const switchModelser = objm.modelser2Manager.switchModelser

// 服务路径
const url = toVR<any>(d, [switchModelser, "url"])
// 服务名称
const name = toVR<any>(d, [switchModelser, "name"])
// 服务列表
const recordLists = toVR<any>(d, [switchModelser, "recordLists"])
// 选择应用
const selectAPP = (item: ApplyType) => {
    name.value = item.name
    url.value = `${objm.modelser2Manager.eSMsTileset.baseUrl}/ts/info/${item.name}`
}

const confirm = () => {
    emit("confirm",url.value)
}

const cancel = () => {
    emit("cancel",url.value)
}


onMounted(() => {
    switchModelser.init()
})

onBeforeUnmount(() => {
})

</script>

<style scoped>
#mark {
    position: absolute;
    z-index: 100000000;
    background: #282b349f;
    left: 0px;
    top: 0px;
    right: 0px;
    bottom: 0px;
}

@media screen and (max-width: 550px) {
    #switchEngine {
        display: none !important;
    }
}

#switchEngine {
    position: absolute;
    display: flex;
    align-items: center;
    right: 30px;
    top: 20px;
}

#confirm {
    position: absolute;
    display: flex;
    flex-direction: column;
    padding: 10px 20px 10px 20px;
    box-sizing: border-box;
    color: black;
    border-radius: 8px;
    border: 1px solid #939e8f;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    width: 630px;
    height: 480px;
}

#confirm>.title {
    padding: 0px 10px;
    border-bottom: 1px solid #000;
}

#confirm>.top {
    padding-top: 10px;
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 10px;
    align-items: center;
}

#confirm>.middle {
    margin: 20px 5px;
    flex-grow: 1;
    display: flex;
    flex-wrap: wrap;
    overflow: auto;
    cursor: pointer;
}

#confirm>.middle>div {
    box-sizing: border-box;
    width: 80px;
    height: 100px;
    margin-right: 12px;
    margin-bottom: 10px;

}

#confirm>.middle>div>img {
    box-sizing: border-box;
    border: 1px solid #939e8f;
}


#confirm>.middle>div>p {
    padding: 0px;
    margin: 0px;
    font-size: 14px;
    text-align: center;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;
    white-space: nowrap;
}

#confirm>.footer {
    display: flex;
    justify-content: flex-end;
    height: 40px;
}

.selected img {
    border: 2px solid #537cfe !important;
}

#confirm .tip {
    width: 100%;
    text-align: center;
    padding-top: 50px;
    font-size: 15px;
    color: #878b92;
    font-style: italic;
    text-shadow: 0.2px 0.5px 0px #878b92;
}

a {
    color: #3385ff;

}

#confirm .to-link {
    padding-left: 10px;
    text-decoration: none;
}

/* button {
    background: #3385ff;
    padding-left: 20px;
    padding-right: 20px;
    height: 32px;
    color: #d6deea;
    border: none;
    cursor: pointer;
    margin-right: 10px;
    margin-bottom: 10px;
}

button:hover {
    background: #004dc2 !important;
} */

input[type=number],
input[type=text] {
    /* background: #282b34; */
    border: 1px solid #454953;
    outline: none;
    height: 32px;
    color: black;
    text-indent: 10px;
    border-radius: 2px;
}

input[type=text]:hover {
    animation-duration: 0.5s;
    border: 1px solid #3385ff;
}
</style>
